/*
 * ListIterator.h
 *
 *  Created on: Apr 25, 2012
 *      Author: REZNIK
 */

#ifndef LISTITERATOR_H_
#define LISTITERATOR_H_

#include "Iterator.h"
#include "Node.h"
#include "LinkedListImpl.h"

namespace cs236703_spring2012_hw2
{

// The Iterator class is used to go over the linked list,
// get and set values, and add and remove nodes.
class ListIterator : public Iterator
{
private:
	LinkedListImpl* list;
	Node* curr;
	int time;
	void checkVersion() const{
		if(time != list->GetVersion())
			throw ConcurrentModificationException();
	};
public:
	ListIterator(LinkedListImpl* list, Node* node, int version);
	// What would happen if the d'tor is not virtual?
	virtual ~ListIterator();
	// Add a new element before the current one
	virtual void AddBefore(int value, bool immutable);
	// Add a new element after the current one
	virtual void AddAfter(int value, bool immutable);
	// Indicate whether there's another element after the current one
	virtual bool HasNext() const;
	// Indicate whether there's another element before the current one
	virtual bool HasPrevious() const;
	// Move iterator to the next element, and return its content
	virtual int Next();
	// Move iterator to the previous element, and return its content
	virtual int Previous();
	// Remove the current element from the list. The element is still accessible
	// to iterators pointing on it, but not to any others.
	virtual void Remove();
	// Set the value of the pointed element.
	virtual void Set(int val);
	// Get the value of the pointed element.
	virtual int Get() const;
};

}


#endif /* LISTITERATOR_H_ */
